<!--
 * @Author: 刘十三
 * @Date: 2023-12-28 14:56:27
 * @LastEditors: 刘十三
 * @LastEditTime: 2024-01-04 20:56:04
 * @FilePath: \dev-1.3.1-nm\dev\pages\internal\linkage\todo\components\informationPlan.vue
 * @Description: 内蒙多员联动 - 信息录入审批（核查安排表单）
-->

<template>
  <view class="form-main">
    <u-form class="u-form-m" :model="planForm" :error-type="['border-bottom', 'toast']" label-width="auto" label-position="top" ref="uForm">
      <u-form-item label="安排情况" prop="plannStatus" :required="isEdit">
        <u-radio-group v-model="planForm.plannStatus" :disabled="!isEdit">
          <u-radio v-for="(item, index) in list" :key="index" :name="item.value">
            {{ item.name }}
          </u-radio>
        </u-radio-group>
      </u-form-item>
      <u-form-item label="安排日期" prop="handleDate" :required="isEdit">
        <u-input placeholder="请选择" v-model="planForm.handleDate" :disabled="true" @click="clickDatekHandle"></u-input>
      </u-form-item>
      <u-form-item label="核查人" prop="nextHandlePersonsName" :required="isEdit">
        <u-input placeholder="提交时选择" v-model="planForm.nextHandlePersonsName" :disabled="true"></u-input>
      </u-form-item>
      <u-form-item label="安排意见" prop="handleComment" :required="isEdit">
        <u-input placeholder="请输入" v-model="planForm.handleComment" type="textarea" height="100" :auto-height="true" :disabled="!isEdit" maxlength="200" />
      </u-form-item>
      <u-form-item label="" prop="" :border-bottom="false">
        <u-row style="width:100%">
          <u-col span="12" class="left-label" text-align="right">{{ planForm.handlePersonsDeptName }}：{{ planForm.handlePersonsName }}</u-col>
          <u-col span="12" class="right-label" text-align="right">{{ planForm.createdAt }}</u-col>
        </u-row>
      </u-form-item>
    </u-form>
    <!-- 日历 -->
    <u-picker mode="time" v-model="showTimeVisable" :params="params" :safe-area-inset-bottom="true" @confirm="changeDate"></u-picker>
  </view>
</template>

<script>
import { uuid } from "@/common/util.js";
import moment from "moment";
export default {
  name: "informationPlan",
  props: {
    isEdit: {
      type: Boolean, // 是否可以编辑  false 不可以编辑
      default: false,
    },
    form: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      list: [
        {
          name: "未安排",
          value: "0",
        },
        {
          name: "已安排",
          value: "1",
        },
      ],
      planForm: {
        id: "",
        plannStatus: "0", // 安排情况 PC端是数字 这里提交需要转换
        handleDate: "", // 安排日期
        handleComment: "", // 安排意见
        nextHandlePersonsId: "", // 下一级审批人ID
        nextHandlePersonsName: "", //  下一级审批人NAME
        handlePersonsName: "", // 当前人
        createdAt: "", // 当前时间
        handlePersonsDeptName: "", //当前人的组织name
      },
      rules: {
        plannStatus: [
          {
            required: true,
            message: "请选择安排情况",
            trigger: ["blur", "change"],
          },
        ],
        handleDate: [
          {
            required: true,
            message: "请选择安排日期",
            trigger: ["blur", "change"],
          },
        ],
        handleComment: [
          {
            required: true,
            message: "请输入安排意见，最多200个字",
            trigger: ["blur", "change"],
          },
        ],
      },
      showTimeVisable: false,
      params: {
        year: true,
        month: true,
        day: true,
        hour: false,
        minute: false,
        second: false,
      },
    };
  },
  methods: {
    clickDatekHandle() {
      if (this.isEdit) {
        this.showTimeVisable = true;
      }
    },
    changeDate(value) {
      this.planForm.handleDate = value.year + "-" + value.month + "-" + value.day;
      this.showTimeVisable = false;
    },
    getCurDate() {
      return moment().format("YYYY-MM-DD");
    },
    getCurTime() {
      return moment().format("YYYY-MM-DD hh:MM:ss");
    },
  },
  mounted() {
    if (this.isEdit) {
      this.$refs.uForm.setRules(this.rules);
      this.planForm.id = uuid();
      this.planForm.handleDate = this.getCurDate();
      this.planForm.handlePersonsDeptName = this.curUser.deptName;
      this.planForm.handlePersonsName = this.curUser.user.personName;
      this.planForm.createdAt = this.getCurDate();
    } else {
      this.planForm = this.form;
    }
  },
};
</script>

<style lang="scss" scoped>
.u-form-m {
  padding: 0px 5px;
}
</style>
